from django.db import models


class State(models.IntegerChoices):
    ONLINE = 1, "在线"
    OFFLINE = 2, "离线"


class Device(models.Model):
    id = models.AutoField(primary_key=True, verbose_name="id")
    name = models.CharField(
        verbose_name="设备名", max_length=20, blank=True, null=True)
    sn = models.CharField(verbose_name="序列号", max_length=20, unique=True)
    brand = models.CharField(verbose_name="厂商", max_length=10)
    version = models.CharField(verbose_name="版本号", max_length=5)
    state = models.SmallIntegerField(
        verbose_name="状态", choices=State.choices, default=State.OFFLINE)

    def __str__(self):
        return '%s-%s' % (self.name, self.id)
